/*
 * Node.h
 *
 *  Created on: Oct 28, 2010
 *      Author: Jacob
 */

#ifndef NODE_H_
#define NODE_H_
#include <string.h>
#include <sstream>
using std::string;
using std::ostringstream;
using std::stringstream;
using std::string;

//REMOVE ME
#include <iostream>
using std::cout;

template<typename T>
class Node
{
public:
	static Node<T>* newNodeFromData(T data);
	T getData();
	void setData(T newData);
	string toString();
	Node();
	Node<T>* parent;
	Node<T>* left;
	Node<T>* right;
	virtual ~Node();
private:
	T data;
	Node(T data);
	void setChildNodesParentToThis(Node<T>* childNode);

};

template<typename T>
Node<T>* Node<T>::newNodeFromData(T data)
{
	return new Node<T> (data);
}

template<typename T>
Node<T>::Node(T data) :
	data(data)
{
	this->left = NULL;
	this->right = NULL;
	this->parent = NULL;
}

template<typename T>
Node<T>::Node()
{
	this->left = NULL;
	this->right = NULL;
	this->parent = NULL;
}

template<typename T>
Node<T>::~Node()
{
	cout << "\nNode Destructor Called on " << this;
	this->parent = NULL;
	this->left = NULL;
	this->right = NULL;
	delete parent;
	delete left;
	delete right;
}

template<typename T>
T Node<T>::getData()
{
	return this->data;
}

template<typename T>
void Node<T>::setData(T newData)
{
	this->data = newData;
}

template<typename T>
string Node<T>::toString()
{
	ostringstream stringStream;

	string lineBreak = "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
	stringStream << lineBreak << "Node: " << this;
	if(left != NULL)
		stringStream << "\nLeft : " << left->toString();
	else
		stringStream << "\nLeft: " << left;
	if(right != NULL)
		stringStream << "\nRight: " << right->toString();
	else
		stringStream << "\nRight " << right;

	stringStream << "\nData: " << data << lineBreak;
	return stringStream.str();
}

#endif /* NODE_H_ */
